<script>
    $(function () {
        <#list table.fields as field>
        <#if (field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate") && field.editable>

        let ${field.propertyName}Lay = {
            fixed: true,
            elem: '#${serviceNameSimple}_${field.propertyName}',
            format: "YYYY-MM-DD<#if field.propertyType == "LocalDateTime"> hh:mm:ss</#if>",
            istime: ${(field.propertyType == "LocalDateTime")?string},
            isclear: false
        };
        laydate(${field.propertyName}Lay);
        <#elseif field.propertyName == "locationId">

        let provinceId = ${r'${(provinceId)!0}'};
        let cityId = ${r'${(cityId)!0}'};
        let locationId = ${r'${(locationId)!0}'};
        </#if>
        </#list>

        formValidate("#${serviceNameSimple}EditForm", {
        <#list table.fields as field>
        <#if field.propertyName == "idx" || field.propertyName == "createTime">
        <#elseif field.editable>
            ${field.propertyName}: {
                required: <#if field.nullable>false<#else>true</#if>,
                maxlength: ${field.length}
            },
        </#if>
        </#list>
        })

        <#list table.fields as field>
        <#if field.propertyName == "locationId">
        $("#${serviceNameSimple}EditForm #provinceId").change(function () {
            locationOptions("#${serviceNameSimple}EditForm #cityId", $(this).val(), cityId, true);
            cityId = 0;
        });
        $("#${serviceNameSimple}EditForm #cityId").change(function () {
            locationOptions("#${serviceNameSimple}EditForm #locationId", $(this).val(), locationId, true);
            locationId = 0;
        });
        locationOptions("#${serviceNameSimple}EditForm #provinceId", 0, provinceId, true);
        provinceId = 0;
        </#if>
        </#list>
    });

    function ${serviceNameSimple}SubmitForm(parentIndex) {
        let isOk = $("#${serviceNameSimple}EditForm").validate().form();
        if (isOk) {
            lglPost("保存${table.comment}", "${r'${base}'}/${table.controllerPath}/save.html", $("#${serviceNameSimple}EditForm").serializeArray(), function (data) {
                closeMsg(parentIndex);
                layer.msg("保存成功");
                $('#${serviceNameSimple}SearchTable').bootstrapTable("refresh");
            });
        }
    }
</script>

<div style="width:680px;padding:15px;height:auto;overflow:auto;">
    <form class="form-horizontal" id="${serviceNameSimple}EditForm">
        <#list table.fields as field>
        <#if field.editable>
        <div class="form-group"<#if field.editableInvisible> style="display:none;"</#if>>
            <label class="col-xs-3 control-label<#if !(field.nullable)> red-star-before</#if>">${field.comment}</label>
            <#if field.select>
            <div class="col-xs-8">
                <select class="form-control" name="${field.propertyName}" id="${field.propertyName}">
                    ${'[#list ${field.propertyName} as item]'}
                    <option value="${r'${item}'}" ${r'[#if'} item==${serviceNameSimple}.${field.propertyName}]selected=selected${'[/#if]'}>${r'${item'}.description}</option>
                    ${'[/#list]'}
                </select>
            <#elseif field.propertyName == "locationId">
            <div class="input-group col-xs-8" style="padding: 0 15px;">
                <select name="provinceId" id="provinceId" class="form-control width-32"></select>
                <select name="cityId" id="cityId" class="form-control width-32" style="margin:0 2%;"></select>
                <select name="locationId" id="locationId" class="form-control width-32"></select>
            <#else>
            <div class="col-xs-8">
                <input type="text" class="form-control<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate"> laydate-icon</#if>" placeholder="${field.comment}" name="${field.propertyName}" id="<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">${serviceNameSimple}_</#if>${field.propertyName}" autocomplete="off" value="${r'${'}<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">((</#if>${serviceNameSimple}.${field.propertyName}<#if field.propertyType == "LocalDateTime" || field.propertyType == "LocalDate">)?string('yyyy-MM-dd<#if field.propertyType == "LocalDateTime"> HH:mm:ss</#if>'))!''</#if>}">
            </#if>
            </div>
        </div>
        <#else>
        <input type="hidden" name="${field.propertyName}" id="${field.propertyName}" value="${r'${'}(${serviceNameSimple}.${field.propertyName})!}">
        </#if>
        </#list>
    </form>
</div>
